/******************************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd.                       */
/*                                                                            */
/*  NAME      = zookeeper_request.c                                           */
/*  NOTE      = ZOOKEEPER协议解析                                             */
/*  DATE      = 2014/05/27 by zhengxd                                         */
/******************************************************************************/
#include <stdio.h>
#include <string.h>
#include <netinet/in.h>

#include "zookeeper_core.h"
#include "zookeeper_common.h"
#include "zookeeper_request.h"

/*******************************************************************************
*  FUNC     :  解析zookeeper create请求
*  ARGS     :  p_st_data(数据包信息)
*           :  p_st_req(请求信息)
*  RTN      :  APM_L7_ANALYZE_FAIL      (FAIL)
*              APM_L7_ANALYZE_SUCC      (SUCC)
*  NOTE     :
*******************************************************************************/
FR_STATIC int __zookeeper_parse_create(Frbyte_Packet *p_st_data
                                       , L7_req_zookeeper *p_st_req)
{
    int i_ret = APM_L7_ANALYZE_SUCC;

    /* 根据源码create = path(string) + data(buffer) + ACLs */
    /* path */
    i_ret = zookeeper_get_string(p_st_data, "path", &p_st_req->st_data_lst);
    if (i_ret == APM_L7_ANALYZE_FAIL)
    {
        frdbg("get create path failed!\n");
        return i_ret;
    }
    /* data */
    i_ret = zookeeper_get_buffer(p_st_data, "data", &p_st_req->st_data_lst);
    if (i_ret == APM_L7_ANALYZE_FAIL)
    {
        frdbg("get create data failed!\n");
        return i_ret;
    }
    /* ACLs */
    i_ret = zookeeper_skip_acl_vector(p_st_data);
    if (i_ret == APM_L7_ANALYZE_FAIL)
    {
        frdbg("skip create ACLs failed!\n");
        return i_ret;
    }
    /* 正确的格式是后面没有其他数据 */
    if (bytebuff_remaining(p_st_data) != 4)
    {
        return APM_L7_ANALYZE_FAIL;
    }
    return APM_L7_ANALYZE_SUCC;
}

/*******************************************************************************
*  FUNC     :  解析zookeeper delete请求
*  ARGS     :  p_st_data(数据包信息)
*           :  p_st_req(请求信息)
*  RTN      :  APM_L7_ANALYZE_FAIL      (FAIL)
*              APM_L7_ANALYZE_SUCC      (SUCC)
*  NOTE     :
*******************************************************************************/
FR_STATIC int __zookeeper_parse_delete(Frbyte_Packet *p_st_data
                                  , L7_req_zookeeper *p_st_req)
{
    int i_ret = APM_L7_ANALYZE_SUCC;

    /* 根据源码delete = path(string) + version(int) */
    /* path */
    i_ret = zookeeper_get_string(p_st_data, "path", &p_st_req->st_data_lst);
    if (i_ret == APM_L7_ANALYZE_FAIL)
    {
        frdbg("get delete path failed!\n");
        return i_ret;
    }
    /* version */
    i_ret = bytebuff_skip(p_st_data, ZOOKEEPER_INT_LEN);
    if (i_ret != FR_SUCC)
    {
        frdbg("skip delete version failed!\n");
        return APM_L7_ANALYZE_FAIL;
    }
    /* 正确的格式是后面没有其他数据 */
    if (bytebuff_remaining(p_st_data))
    {
        return APM_L7_ANALYZE_FAIL;
    }
    return APM_L7_ANALYZE_SUCC;
}

/*******************************************************************************
*  FUNC     :  解析zookeeper exists请求
*  ARGS     :  p_st_data(数据包信息)
*           :  p_st_req(请求信息)
*  RTN      :  APM_L7_ANALYZE_FAIL      (FAIL)
*              APM_L7_ANALYZE_SUCC      (SUCC)
*  NOTE     :
*******************************************************************************/
FR_STATIC int __zookeeper_parse_exists(Frbyte_Packet *p_st_data
                                  , L7_req_zookeeper *p_st_req)
{
    int i_ret = APM_L7_ANALYZE_SUCC;

    /* 根据源码exists = path(string) + watch(Bool) */
    /* path */
    i_ret = zookeeper_get_string(p_st_data, "path", &p_st_req->st_data_lst);
    if (i_ret == APM_L7_ANALYZE_FAIL)
    {
        frdbg("get exists path failed!\n");
        return i_ret;
    }
    /* watch */
    i_ret = bytebuff_get_char(p_st_data, &p_st_req->u8_watch_flg);
    if (i_ret != FR_SUCC)
    {
        frdbg("skip exists watch failed!\n");
        return APM_L7_ANALYZE_FAIL;
    }
    /* 正确的格式是后面没有其他数据 */
    if (bytebuff_remaining(p_st_data))
    {
        return APM_L7_ANALYZE_FAIL;
    }
    return APM_L7_ANALYZE_SUCC;
}

/*******************************************************************************
*  FUNC     :  解析zookeeper getdata请求
*  ARGS     :  p_st_data(数据包信息)
*           :  p_st_req(请求信息)
*  RTN      :  APM_L7_ANALYZE_FAIL      (FAIL)
*              APM_L7_ANALYZE_SUCC      (SUCC)
*  NOTE     :
*******************************************************************************/
FR_STATIC int __zookeeper_parse_getdata(Frbyte_Packet *p_st_data
                                   , L7_req_zookeeper *p_st_req)
{
    int i_ret = APM_L7_ANALYZE_SUCC;

    /* 根据源码getdata = path(string) + watch(Bool) */
    /* path */
    i_ret = zookeeper_get_string(p_st_data, "path", &p_st_req->st_data_lst);
    if (i_ret == APM_L7_ANALYZE_FAIL)
    {
        frdbg("get getdata path failed!\n");
        return i_ret;
    }
    /* watch */
    i_ret = bytebuff_get_char(p_st_data ,&p_st_req->u8_watch_flg);
    if (i_ret != FR_SUCC)
    {
        frdbg("skip getdata watch failed!\n");
        return APM_L7_ANALYZE_FAIL;
    }
    /* 正确的格式是后面没有其他数据 */
    if (bytebuff_remaining(p_st_data))
    {
        return APM_L7_ANALYZE_FAIL;
    }
    return APM_L7_ANALYZE_SUCC;
}

/*******************************************************************************
*  FUNC     :  解析zookeeper setdata请求
*  ARGS     :  p_st_data(数据包信息)
*           :  p_st_req(请求信息)
*  RTN      :  APM_L7_ANALYZE_FAIL      (FAIL)
*              APM_L7_ANALYZE_SUCC      (SUCC)
*  NOTE     :
*******************************************************************************/
FR_STATIC int __zookeeper_parse_setdata(Frbyte_Packet *p_st_data
                                   , L7_req_zookeeper *p_st_req)
{
    int i_ret = APM_L7_ANALYZE_SUCC;

    /* 根据源码setdata = path(string) + data(buffer) + version(Int) */
    /* path */
    i_ret = zookeeper_get_string(p_st_data, "path", &p_st_req->st_data_lst);
    if (i_ret == APM_L7_ANALYZE_FAIL)
    {
        frdbg("get setdata path failed!\n");
        return i_ret;
    }
    /* data */
    i_ret = zookeeper_get_string(p_st_data, "data", &p_st_req->st_data_lst);
    if (i_ret == APM_L7_ANALYZE_FAIL)
    {
        frdbg("get setdata data failed!\n");
        return i_ret;
    }
    /* version */
    i_ret = bytebuff_skip(p_st_data, ZOOKEEPER_INT_LEN);
    if (i_ret != FR_SUCC)
    {
        frdbg("skip setdata version failed!\n");
        return APM_L7_ANALYZE_FAIL;
    }
    /* 正确的格式是后面没有其他数据 */
    if (bytebuff_remaining(p_st_data))
    {
        return APM_L7_ANALYZE_FAIL;
    }
    return APM_L7_ANALYZE_SUCC;
}

/*******************************************************************************
*  FUNC     :  解析zookeeper getacl请求
*  ARGS     :  p_st_data(数据包信息)
*           :  p_st_req(请求信息)
*  RTN      :  APM_L7_ANALYZE_FAIL      (FAIL)
*              APM_L7_ANALYZE_SUCC      (SUCC)
*  NOTE     :
*******************************************************************************/
FR_STATIC int __zookeeper_parse_getacl(Frbyte_Packet *p_st_data
                                  , L7_req_zookeeper *p_st_req)
{
    int i_ret = APM_L7_ANALYZE_SUCC;

    /* 根据源码 getacl = path(string) */
    /* path */
    i_ret = zookeeper_get_string(p_st_data, "path", &p_st_req->st_data_lst);
    if (i_ret == APM_L7_ANALYZE_FAIL)
    {
        frdbg("get getacl path failed!\n");
        return i_ret;
    }
    /* 正确的格式是后面没有其他数据 */
    if (bytebuff_remaining(p_st_data))
    {
        return APM_L7_ANALYZE_FAIL;
    }
    return APM_L7_ANALYZE_SUCC;
}

/*******************************************************************************
*  FUNC     :  解析zookeeper setacl请求
*  ARGS     :  p_st_data(数据包信息)
*           :  p_st_req(请求信息)
*  RTN      :  APM_L7_ANALYZE_FAIL      (FAIL)
*              APM_L7_ANALYZE_SUCC      (SUCC)
*  NOTE     :
*******************************************************************************/
FR_STATIC int __zookeeper_parse_setacl(Frbyte_Packet *p_st_data
                                  , L7_req_zookeeper *p_st_req)
{
    int i_ret = APM_L7_ANALYZE_SUCC;

    /* 根据源码 setacl = path(string) + acl(ACLs) + version(Int)  */
    /* path */
    i_ret = zookeeper_get_string(p_st_data, "path", &p_st_req->st_data_lst);
    if (i_ret == APM_L7_ANALYZE_FAIL)
    {
        frdbg("get setacl path failed!\n");
        return i_ret;
    }
    /* acl */
    i_ret = zookeeper_skip_acl_vector(p_st_data);
    if (i_ret == APM_L7_ANALYZE_FAIL)
    {
        frdbg("skip setacl ACLs failed!\n");
        return i_ret;
    }
    /* version */
    i_ret = bytebuff_skip(p_st_data, ZOOKEEPER_INT_LEN);
    if (i_ret != FR_SUCC)
    {
        frdbg("skip setacl version failed!\n");
        return APM_L7_ANALYZE_FAIL;
    }
    /* 正确的格式是后面没有其他数据 */
    if (bytebuff_remaining(p_st_data))
    {
        return APM_L7_ANALYZE_FAIL;
    }
    return APM_L7_ANALYZE_SUCC;
}

/*******************************************************************************
*  FUNC     :  解析zookeeper getchildren请求
*  ARGS     :  p_st_data(数据包信息)
*           :  p_st_req(请求信息)
*  RTN      :  APM_L7_ANALYZE_FAIL      (FAIL)
*              APM_L7_ANALYZE_SUCC      (SUCC)
*  NOTE     :
*******************************************************************************/
FR_STATIC int __zookeeper_parse_getchildren(Frbyte_Packet *p_st_data
                                       , L7_req_zookeeper *p_st_req)
{
    int i_ret = APM_L7_ANALYZE_SUCC;

    /* 根据源码 getchildren = path(string) + watch(Bool)  */
    /* path */
    i_ret = zookeeper_get_string(p_st_data, "path", &p_st_req->st_data_lst);
    if (i_ret == APM_L7_ANALYZE_FAIL)
    {
        frdbg("get getchildren path failed!\n");
        return i_ret;
    }
    /* watch */
    i_ret = bytebuff_get_char(p_st_data ,&p_st_req->u8_watch_flg);
    if (i_ret != FR_SUCC)
    {
        frdbg("skip getchildren watch failed!\n");
        return APM_L7_ANALYZE_FAIL;
    }
    /* 正确的格式是后面没有其他数据 */
    if (bytebuff_remaining(p_st_data))
    {
        return APM_L7_ANALYZE_FAIL;
    }
    return APM_L7_ANALYZE_SUCC;
}

/*******************************************************************************
*  FUNC     :  解析zookeeper sync请求
*  ARGS     :  p_st_data(数据包信息)
*           :  p_st_req(请求信息)
*  RTN      :  APM_L7_ANALYZE_FAIL      (FAIL)
*              APM_L7_ANALYZE_SUCC      (SUCC)
*  NOTE     :
*******************************************************************************/
FR_STATIC int __zookeeper_parse_sync(Frbyte_Packet *p_st_data
                                , L7_req_zookeeper *p_st_req)
{
    int i_ret = APM_L7_ANALYZE_SUCC;

    /* 根据源码 sync = path(string) + watch(Bool)  */
    /* path */
    i_ret = zookeeper_get_string(p_st_data, "path", &p_st_req->st_data_lst);
    if (i_ret == APM_L7_ANALYZE_FAIL)
    {
        frdbg("get sync path failed!\n");
        return i_ret;
    }
    /* 正确的格式是后面没有其他数据 */
    if (bytebuff_remaining(p_st_data))
    {
        return APM_L7_ANALYZE_FAIL;
    }
    return APM_L7_ANALYZE_SUCC;
}

/*******************************************************************************
*  FUNC     :  解析zookeeper getchildren2请求
*  ARGS     :  p_st_data(数据包信息)
*           :  p_st_req(请求信息)
*  RTN      :  APM_L7_ANALYZE_FAIL      (FAIL)
*              APM_L7_ANALYZE_SUCC      (SUCC)
*  NOTE     :
*******************************************************************************/
FR_STATIC int __zookeeper_parse_getchildren2(Frbyte_Packet *p_st_data
                                       , L7_req_zookeeper *p_st_req)
{
    int i_ret = APM_L7_ANALYZE_SUCC;

    /* 根据源码 getchildren2 = path(string) + watch(Bool)  */
    /* path */
    i_ret = zookeeper_get_string(p_st_data, "path", &p_st_req->st_data_lst);
    if (i_ret == APM_L7_ANALYZE_FAIL)
    {
        frdbg("get getchildren2 path failed!\n");
        return i_ret;
    }
    /* watch */
    i_ret = bytebuff_get_char(p_st_data ,&p_st_req->u8_watch_flg);
    if (i_ret != FR_SUCC)
    {
        frdbg("skip getchildren2 watch failed!\n");
        return APM_L7_ANALYZE_FAIL;
    }
    /* 正确的格式是后面没有其他数据 */
    if (bytebuff_remaining(p_st_data))
    {
        return APM_L7_ANALYZE_FAIL;
    }
    return APM_L7_ANALYZE_SUCC;
}

/*******************************************************************************
*  FUNC     :  解析zookeeper setwatches请求
*  ARGS     :  p_st_data(数据包信息)
*           :  p_st_req(请求信息)
*  RTN      :  APM_L7_ANALYZE_FAIL      (FAIL)
*              APM_L7_ANALYZE_SUCC      (SUCC)
*  NOTE     :
*******************************************************************************/
FR_STATIC int __zookeeper_parse_setwatches(Frbyte_Packet *p_st_data
                                      , L7_req_zookeeper *p_st_req)
{
    int i_ret = APM_L7_ANALYZE_SUCC;
    uint64_t u64_relative_zxid = 0;

    /* 根据源码 setwatches = relativeZxid(Long) + dataWatches(String vector)
       + existWatches(String vector) + childWatches(String vector)  */
    /* path */
    i_ret = zookeeper_get_string(p_st_data, "path", &p_st_req->st_data_lst);
    if (i_ret == APM_L7_ANALYZE_FAIL)
    {
        frdbg("get setwatches path failed!\n");
        return i_ret;
    }
    /* relativeZxid */
    i_ret = bytebuff_get_long(p_st_data, ZOOKEEPER_LONG_LEN
                             , &u64_relative_zxid, BYTE_BIG_ENDIAN);
    if (i_ret != FR_SUCC)
    {
        frdbg("skip setwatches watch failed!\n");
        return APM_L7_ANALYZE_FAIL;
    }
    /* dataWatches */
    i_ret = zookeeper_get_str_vector(p_st_data, "dataWatches"
                                     , &p_st_req->st_data_lst);
    if (i_ret != FR_SUCC)
    {
        frdbg("get setwatches dataWatches failed!\n");
        return APM_L7_ANALYZE_FAIL;
    }
    /* dataWatches */
    i_ret = zookeeper_get_str_vector(p_st_data, "existWatches"
                                     , &p_st_req->st_data_lst);
    if (i_ret != FR_SUCC)
    {
        frdbg("get setwatches existWatches failed!\n");
        return APM_L7_ANALYZE_FAIL;
    }
    /* dataWatches */
    i_ret = zookeeper_get_str_vector(p_st_data, "childWatches"
                                     , &p_st_req->st_data_lst);
    if (i_ret != FR_SUCC)
    {
        frdbg("get setwatches childWatches failed!\n");
        return APM_L7_ANALYZE_FAIL;
    }
    /* 正确的格式是后面没有其他数据 */
    if (bytebuff_remaining(p_st_data))
    {
        return APM_L7_ANALYZE_FAIL;
    }
    return APM_L7_ANALYZE_SUCC;
}


/*******************************************************************************
*  FUNC     :  解析zookeeper setwatches请求
*  ARGS     :  p_st_data(数据包信息)
*           :  p_st_req(请求信息)
*  RTN      :  APM_L7_ANALYZE_FAIL      (FAIL)
*              APM_L7_ANALYZE_SUCC      (SUCC)
*  NOTE     :
*******************************************************************************/
FR_STATIC int __zookeeper_parse_auth(Frbyte_Packet *p_st_data
                                , L7_req_zookeeper *p_st_req)
{
    int i_ret = APM_L7_ANALYZE_SUCC;

    /* 根据源码 setauth = type(int) + scheme(String) + auth(buffer)
       + existWatches(String vector) + childWatches(String vector)  */
    /* 跳过type */
    i_ret = bytebuff_skip(p_st_data, ZOOKEEPER_INT_LEN);
    if (i_ret != FR_SUCC)
    {
        frdbg("skip setauth version failed!\n");
        return APM_L7_ANALYZE_FAIL;
    }

    /* scheme */
    i_ret = zookeeper_get_string(p_st_data, "scheme", &p_st_req->st_data_lst);
    if (i_ret == APM_L7_ANALYZE_FAIL)
    {
        frdbg("get setauth scheme failed!\n");
        return i_ret;
    }

    /* auth */
    i_ret = zookeeper_get_buffer(p_st_data, "auth", &p_st_req->st_data_lst);
    if (i_ret == APM_L7_ANALYZE_FAIL)
    {
        frdbg("get setauth auth failed!\n");
        return i_ret;
    }

    /* 正确的格式是后面没有其他数据 */
    if (bytebuff_remaining(p_st_data))
    {
        return APM_L7_ANALYZE_FAIL;
    }
    return APM_L7_ANALYZE_SUCC;
}

/*******************************************************************************
*  FUNC     :  解析zookeeper请求
*  ARGS     :  p_st_conn(入力链接信息)
*           :  p_st_private(私有session数据)
*           :  p_st_hash_report(保存Frreport_data)
*  RTN      :  APM_L7_ANALYZE_FAIL      (FAIL)
*              APM_L7_ANALYZE_SUCC      (SUCC)
*  NOTE     :
*******************************************************************************/
int zookeeper_parse_req(Conntrack *p_st_conn
                       , L7session_zookeeper_private *p_st_private
                       , Frhash_header *p_st_hash_report)
{
    uint32_t u32_xid = 0;
    uint32_t u32_type = 0;
    uint32_t u32_conn_xid = 0;
    int i_ret = APM_L7_ANALYZE_SUCC;
    L7_req_zookeeper *p_st_req = NULL;
    L7_fragment_zookeeper *p_st_fragment = p_st_private->p_st_fragment;
    Frbyte_Packet *p_st_data = p_st_fragment->p_st_data;
     Frhash_header *p_hash_header = p_st_private->p_hash_header;
    Frlist_node *p_st_node = NULL;

    /* 创建request */
    p_st_req = (L7_req_zookeeper *)frmalloc(sizeof(L7_req_zookeeper));
    if (p_st_req == NULL)
    {
        frdbg("create request failed!\n");
        zookeeper_init_curr_info(p_st_private);
        return APM_L7_ANALYZE_FAIL;
    }
    memset(p_st_req,0x0, sizeof(L7_req_zookeeper));

    /* 取得xid */
    i_ret = bytebuff_get_int(p_st_data, ZOOKEEPER_XID_LEN
                             , &u32_xid, BYTE_BIG_ENDIAN);
    if (i_ret != FR_SUCC)
    {
        frdbg("get xid failed\n");
        return APM_L7_ANALYZE_FAIL;
    }
    /* 取得type */
    i_ret = bytebuff_get_int(p_st_data, ZOOKEEPER_TYPE_LEN
                             , &u32_type, BYTE_BIG_ENDIAN);
    if (i_ret != FR_SUCC)
    {
        frdbg("get type failed\n");
        zookeeper_destroy_req(&p_st_req);
        return APM_L7_ANALYZE_FAIL;
    }
    /* 设置xid和type */
    p_st_req->i_req_xid = (int)u32_xid;
    p_st_req->i_req_type = (int)u32_type;

    switch (p_st_req->i_req_type)
    {
        case ZOOKEEPER_CREATE_OP:
            i_ret = __zookeeper_parse_create(p_st_data, p_st_req);
            break;

        case ZOOKEEPER_DELETE_OP:
            i_ret = __zookeeper_parse_delete(p_st_data, p_st_req);
            break;

        case ZOOKEEPER_EXISTS_OP:
            i_ret = __zookeeper_parse_exists(p_st_data, p_st_req);
            break;

        case ZOOKEEPER_GETDATA_OP:
            i_ret = __zookeeper_parse_getdata(p_st_data, p_st_req);
            break;

        case ZOOKEEPER_SETDATA_OP:
            i_ret = __zookeeper_parse_setdata(p_st_data, p_st_req);
            break;

        case ZOOKEEPER_GETACL_OP:
            i_ret = __zookeeper_parse_getacl(p_st_data, p_st_req);
            break;

        case ZOOKEEPER_SETACL_OP:
            i_ret = __zookeeper_parse_setacl(p_st_data, p_st_req);
            break;

        case ZOOKEEPER_GETCHILDREN_OP:
            i_ret = __zookeeper_parse_getchildren(p_st_data, p_st_req);
            break;

        case ZOOKEEPER_SYNC_OP:
            i_ret = __zookeeper_parse_sync(p_st_data, p_st_req);
            break;

        case ZOOKEEPER_GETCHILDREN2_OP:
            i_ret = __zookeeper_parse_getchildren2(p_st_data, p_st_req);
            break;

        case ZOOKEEPER_CHECK_OP:
            //i_ret = __zookeeper_parse_check(p_st_data, p_st_req);
            printf("ZOOKEEPER_CHECK_OP unsupport now!\n");
            i_ret = APM_L7_ANALYZE_FAIL;
            break;

        case ZOOKEEPER_MULTI_OP:
            //i_ret = __zookeeper_parse_multi(p_st_data, p_st_req);
            printf("ZOOKEEPER_MULTI_OP unsupport now!\n");
            i_ret = APM_L7_ANALYZE_FAIL;
            break;

        /* close没有内容 */
        case ZOOKEEPER_CLOSE_OP:
            if (bytebuff_remaining(p_st_data))
            {
                i_ret = APM_L7_ANALYZE_FAIL;
            }
            else
            {
                i_ret = APM_L7_ANALYZE_SUCC;
            }
            break;

        /* 忽略PING内容 */
        case ZOOKEEPER_PING_OP:
            i_ret = APM_L7_ANALYZE_SUCC;
            break;

        case ZOOKEEPER_SETWATCHES_OP:
            i_ret = __zookeeper_parse_setwatches(p_st_data, p_st_req);
            break;

        case ZOOKEEPER_SETAUTH_OP:
            i_ret = __zookeeper_parse_auth(p_st_data, p_st_req);
            break;

        /* 请求 */
        case 0:
            i_ret = bytebuff_get_int(p_st_data, ZOOKEEPER_TYPE_LEN
                                     , &u32_conn_xid, BYTE_BIG_ENDIAN);
            if (i_ret != FR_SUCC || u32_conn_xid != 0)
            {
                i_ret = APM_L7_ANALYZE_FAIL;
                break;
            }
            p_st_req->i_req_type = ZOOKEEPER_CONNECT_OP;
            break;

        default:
            i_ret = APM_L7_ANALYZE_FAIL;
            break;
    }

    if (i_ret == APM_L7_ANALYZE_FAIL)
    {
        frdbg("parse request[%d] failed!\n", p_st_req->i_req_type);
        zookeeper_destroy_req(&p_st_req);
        zookeeper_init_curr_info(p_st_private);
        return APM_L7_ANALYZE_FAIL;
    }
    p_st_req->ul_req_sequence = frct_seq_increase(p_st_conn);
    p_st_req->ui_total_len = p_st_fragment->ui_total_len;
    p_st_req->st_start_timestamp = p_st_fragment->st_start_timestamp;
    p_st_req->st_end_timestamp = p_st_fragment->st_end_timestamp;
    p_st_req->ul_send_time_us = zookeeper_get_interval_time(&p_st_req->st_start_timestamp
                                                            , &p_st_req->st_end_timestamp);
    /* 上报request信息 */
    i_ret = zookeeper_report_data(p_st_conn, p_st_private, p_st_req, p_st_hash_report, FR_NO);
    /* 追加request节点到hash */
    frhash2_delLong(p_hash_header, p_st_req->i_req_xid, zookeeper_req_node_free);
    /* 创建hash节点 */
    p_st_node = frlist_node_create(p_st_req);
    if (p_st_node == NULL)
    {
        zookeeper_init_fragment(p_st_fragment);
        zookeeper_destroy_req(&p_st_req);
        return APM_L7_ANALYZE_FAIL;
    }
    frhash2_addLong(p_hash_header, p_st_req->i_req_xid, p_st_node);

    zookeeper_init_fragment(p_st_fragment);
    return i_ret;
}
